<?php
/**
 * test case for Webappkit class
 * @author J.Ducastel <jeremie@ducastel.name>
 */
class TestWebappkit extends UnitTestCase {

	/*function TestWebappkit() {
		$this->UnitTestCase('Testing Webappkit class');

		// $this->kit=webappkit::getKit('webappkit/tests');
		// $this->assertIsA($this->kit,'webappkit');
	}*/

	/**
	 * here we use the webappkit tests kit itself as an exemple kit
	 */
	function setUp() {
		// kit id to test
		$this->id='webappkit.testkit';
	}

	function tearDown() {

	}

	function testStaticMethods() {
		$this->assertIsA(Webappkit::timecounter(),'float',"timecounter doesn't return a float");

		$this->assertTrue(Webappkit::checkKit('webappkit.testkit'));
		// $this->assertError(Webappkit::checkKit('i/do/not/exist'));
		$this->assertFalse(Webappkit::checkKit('i/do/not/exist'));
		$this->assertFalse(Webappkit::checkKit('i/do/not/exist'));

		$this->assertIsA(Webappkit::checkId($this->id),'string');
		$this->assertFalse(Webappkit::checkId('with spaces'));

		$path=Webappkit::getPathFromId($this->id);
		$this->assertIsA($path,'string',"path ($path) is not a string");
		$this->assertTrue(file_exists($path),"invalid path returned ($path)");

		$cfg=Webappkit::getCfgFromId($this->id);
		$this->assertIsA($cfg,'array',"config is not an array");
		$this->assertIsA($cfg['kit']['version'],'string',"no kit version in cfg");

		$version=Webappkit::loadKit($this->id);
		$this->assertIsA($version,'string',"loadKit should return version loaded. %s");


	}

	function testConstructor() {
		$kit=&Webappkit::getkit('webappkit.testkit');
		$this->assertIsA($kit,'webappkit');

		$kit2=&Webappkit::getkit('webappkit.testkit');
		$this->assertReference($kit,$kit2,"Kits should be singletons ! %s");

		$kit3=&Webappkit::getkit('webappkit/testkit');
		$this->assertReference($kit,$kit3,"Kits should be singletons, using both / or dot level separators ! %s");

		// checking tools
		foreach ($this->tools as $name => $class) {
			$this->assertIsA($kit->$name,'wakTool');
			$this->assertIsA($kit->$name,$class);
		}
		// $this->expectError();
		$this->assertError($f=Webappkit::getKit('i am not a kit'));
		$this->assertFalse($f);
		// $this->expectError();
		$this->assertError($f=Webappkit::getKit('i/am/not/a/kit/either'));
		$this->assertFalse($f);
		//Webappkit::getKit('i am not a kit');

		// $this->assertError();
		//$this->assertError(Webappkit::getKit('i/am/not/a/kit/either'));
	}

	function testInstanceMethods() {
		$kit=&Webappkit::getkit('webappkit.testkit');

		$this->assertEqual($kit->getId(),$this->id);

		$path=$kit->getPath($id);
		$this->assertIsA($path,'string',"invalid path %s");
		$this->assertTrue(file_exists($path),"path doesn't exist. ($path)");

		$cfg=$kit->getCfg();
		$this->assertIsA($cfg,'array',"getCfg() should return kit's configuration array");
		// $this->assertEqual($cfg,$this->cfg);
	}

	/*function testFail() {
		$this->assertTrue(false);
		$this->assertError();
		$this->assertTrue(trigger_error("une erreur"));
	}*/

}
?>
